<template>
	<view :style="viewColor" style="min-height: 100vh;">
		<view class="navTabBox" v-if="tabIndex < 3">
			<view class="longTab">
				<view class="tab-item" v-for="(item,index) in tabList" :key="index" :class="{'on':index == tabIndex-1}" @click="bindTab(index)"><text>{{item.title}}</text></view>
			</view>
		</view>
		<view class="circle-list" v-if="circleList.length" style="padding-bottom: 130rpx;">
			<view class='circle-item' v-for="(item, index) in circleList" :key="index">
				<view class='circle-item-top'>
					<view class='circle-item-avatar'>
						<img :src="item.avatar" />
					</view>
					<view class='circle-item-info'>
						<view class='circle-item-title'>{{item.title}}</view>
						<view class="circle-item-gz">
							<image class="circle-item-gz-icon" :src="domain + '/uploads/default/20230628/2c7d68b982302e32ccfa8c0a3d922319.png'" />
							<view  class="circle-item-gz-num">{{item.user_circle_count}}粉丝</view>
						</view>
						<view class="circle-item-gz-user" v-if="item.user_circle.length">
							<image class="circle-item-gz-avatar" v-for="(v,i) in item.user_circle" :key="i" :src="v.user.avatar || '/static/images/f.png'" />
							<image class="circle-item-gz-avatar" :src="domain + '/uploads/default/20230629/436303b1fccbd3e1714b11990d5b7e28.png'" />
							<view class="circle-item-gz-tl">{{item.circle_community_count}} 人在讨论</view>
						</view>
					</view>
					<view class='circle-item-button2' v-if="tabIndex == 1">
						<view class="circle-item-button-b">
							<view class="circle-item-button_btn" @click="getCircleInfo(item.id)" style="background-color: #48B120;">进群</view>
							<button class="circle-item-button_btn" open-type="share" @click="setShareInfo(item)" style="padding: 8rpx 42rpx;font-size: 26rpx;margin-top: 30rpx;">分享赚佣</button>
							<!-- <view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'home_circle_promotion')">首页推广</view>
							<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'circle_promotion')">热门推广</view>
							<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'label_circle_promotion')">行业推广</view> -->
						</view>
					</view>
					<view class='circle-item-button2 acea-center' v-if="tabIndex == 2">
						<!-- <view class="circle-item-status c-ok" v-if="item.is_detection == 1">审核成功</view>
						<view class="circle-item-status c-no" v-else-if="item.is_detection == 2">审核失败</view>
						<view class="circle-item-status c-status" v-else>审核中</view> -->
						<view class="circle-item-button-b">
							<view class="circle-item-button_btn" @click="getCircleInfo(item.id)" style="background-color: #48B120; color: #030502;">进群</view>
							<!-- <view class="circle-item-button_btn" v-if="item.is_detection != 0" @click="editCircle(item.id)">编辑</view>
							<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'home_circle_promotion')">首页推广</view>
							<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'circle_promotion')">热门推广</view>
							<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'label_circle_promotion')">行业推广</view> -->
						</view>
					</view>
					<view class='circle-item-button2' v-if="tabIndex == 3">
						<view class="circle-item-button-b">
							<view class="circle-item-button_btn" @click="getCircleInfo(item.id)">进群</view>
						</view>
					</view>
					<view class='circle-item-button2' v-if="tabIndex == 4">
						<view class="circle-item-button-b">
							<view class="circle-item-button_btn" :class="item.is_user_circle ? 'is_user_circle' : ''" @click="getCircleInfo(item.id)">{{item.is_user_circle ? '进群' : '加群'}}</view>
						</view>
					</view>
				</view>
				<view class="acea-center more_btn" v-if="tabIndex == 2">
					<view class="left_btn acea-center">
						<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'home_circle_promotion')">上首页</view>
						<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'circle_promotion')">热圈榜</view>
						<view class="circle-item-button_btn" v-if="item.is_detection == 1" @click="circlePromotion(item, 'label_circle_promotion')">行业榜</view>
					</view>
					<view class="right_btn acea-center">
						<view class="circle-item-button_btn" style="background-color: #fff; border: 1rpx solid #1C211D" @click="editCircle(item.id)">编辑</view>
						<button class="circle-item-button_btn" open-type="share" @click="setShareInfo(item)">分享</button>
					</view>
				</view>
				<view class="circle-item-fail-msg" v-if="item.is_detection == 2">失败原因：{{item.fail_msg}}</view>
			</view>
		</view>
		<view class="create-circle">
			<view class="create-circle-btn" @click="authTo('/pages/extends/circle_create/index')">创建圈子</view>
		</view>
		<!-- <view class='noCommodity'>
			<view class='pictrue'>
				<image src='https://ly.jukee.net/static/images/noCoupon.png'></image>
			</view>
		</view> -->
		<paymentData :payMode="payMode" :pay_close="pay_close" :is-call="true" @onChangeFun="onChangeFun" :payTitle="'推广到期时间'" :payGroupName="pay_group_name" :userCount="userCount" :unit="'天'" :rechargeType="recharge_type" :extends="payment_data_extends"></paymentData>
		<authorize @onLoadFun="onLoadFun" :isAuto="isAuto" :isShowAuth="isShowAuth" @authColse="authColse"></authorize>
	</view>
</template>

<script>
	 
	let app = getApp();
	import {
		getUserListCircle,
		getAttentionCircle
	} from '@/api/circle.js';
	import {
		mapGetters
	} from "vuex";
	import authorize from '@/components/Authorize';
	import paymentData from '@/components/payDataList';
	import { configMap } from '@/utils';
	import { HTTP_REQUEST_URL } from '@/config/app';
	import { getUserInfo } from '@/api/user.js';
	export default {
		components: {
			authorize,
			paymentData
		},
		data() {
			return {
				domain: HTTP_REQUEST_URL,
				loading: false,
				isAuto: false, //没有授权的不会自动授权
				isShowAuth: false ,//是否隐藏授权
				tabIndex:1,
				tabList:[
					{
						title:'已加入的圈子'
					},
					{
						title:'我创建的圈子'
					}
				],
				limit:15,
				page:1,
				isScroll:true,
				moneyBg: '/static/images/couponBg',
				circleList: [],
				pay_close: false,
				payment_data_extends: {},
				userCount: '',
				payMode: [{
					name: '微信支付',
					icon: 'icon-weixinzhifu',
					value: 'wechat',
					title: '微信快捷支付',
					payStatus: true
					}
					// #ifdef H5 ||APP-PLUS
					,
					{
					name: '支付宝支付',
					icon: 'icon-zhifubao',
					value: 'alipay',
					title: '支付宝支付',
					payStatus: true
					}
					// #endif
					,
					{
						name: "余额支付",
						icon: "icon-yuezhifu",
						value: 'balance',
						title: '可用余额:',
						number: 0,
						payStatus: this.$store.getters.globalData.yue_pay_status
					}
				],
				community_id: '',// 查看服务 视频 续期绑定圈子列表ID
				pay_group_name: 'circle_promotion',
				recharge_type: 2, // 2热门圈子推广订单 7行业圈子推广订单
				share: {
					title: '我的圈子',
					url: '',
					imageUrl: ''
				}
			};
		},
		computed: configMap(['hide_mer_status'], mapGetters(['isLogin','viewColor','keyColor'])),
		onLoad(options) {
			if (this.isLogin) {
				if(options.type) {
					this.tabIndex = options.type
					if(options.type == 3) {
						uni.setNavigationBarTitle({
							title: '圈子推广'
						})
					} else if(options.type == 4) {
						// 查看服务 视频 续期绑定圈子列表
						this.community_id = options.community_id;
						uni.setNavigationBarTitle({
							title: '推广圈子'
						})
					}
				}
				this.getUserInfo();
				this.getUseListCircle()
			} else {
                this.isAuto = true;
                this.isShowAuth = true
			}
		},
		mounted: function() {
		},
		methods: {
			/**
			 * 授权回调
			 */
			onLoadFun: function() {
				this.isShowAuth = false;
				return uni.switchTab({
					url: '/pages/user/index'
				});
			},
			// 授权关闭
			authColse: function(e) {
				this.isShowAuth = e
			},
			bindTab(index){
				this.tabIndex = index+1
				this.page =1
				this.isScroll = true
				this.circleList = [];
				this.getUseListCircle();
			},
			/**
			 * 获取领取优惠券列表
			 */
			getUseListCircle: function() {
				let that = this;
				if(!this.isScroll) return
				getUserListCircle({
					type: this.tabIndex,
					community_id: this.community_id,
					page:this.page,
					limit:this.limit
				}).then(res => {
					that.loading = true;
					that.circleList = that.circleList.concat(res.data.list)
					that.isScroll = that.circleList.length<res.data.count
					that.page++
				})
			},
			editCircle(id) {
				this.$util.Tips('/pages/extends/circle_create/index?id='+id);
			},
			/* getCircleInfo(id) {
				this.$util.Tips('/pages/extends/circle_create/circle_info?id='+id);
			}, */
			getCircleInfo(circle_id) {
				let that = this;
				if(!that.isLogin) return that.$util.Tips({title:'请先登录'}, {tab: 1, url: '/pages/user/index'})
				getAttentionCircle(circle_id).then(res=>{
					if(res.status == 200 && res.data.pay_type){
						return that.$util.Tips('/pages/extends/circle_create/circle_info?id='+circle_id+'&check_nav=1')
					}
					return that.$util.Tips('/pages/extends/circle_create/circle_pay?id='+circle_id);
				}).catch(err=>{
					that.$util.Tips({title: err})
				})
			},
			authTo(url) {
				this.$util.Tips(url);
			},
			// 人脉圈推广
			circlePromotion(data, pay_group_name) {
				if (pay_group_name == 'home_circle_promotion') {
					this.recharge_type = 8;
					this.userCount = data.home_promo_exp
				} else if (pay_group_name == 'label_circle_promotion') {
					this.recharge_type = 7;
					this.userCount = data.ind_promo_exp
				} else {
					this.recharge_type = 2;
					this.userCount = data.hp_promo_exp
				}
				this.pay_group_name = pay_group_name;
				this.payment_data_extends = {
					circle_id: data.id
				}
				this.pay_close = true;
			},
			/**
			 * 获取个人用户信息
			 */
			getUserInfo: function() {
				let that = this;
				getUserInfo().then(res => {
					that.userInfo = res.data;
					// #ifdef H5 ||APP-PLUS
					that.payMode[2].number = res.data.now_money;
					// #endif
					// #ifndef H5 ||APP-PLUS
					that.payMode[1].number = res.data.now_money;
					// #endif
				});
			},
			onChangeFun: function(e) {
				let opt = e;
				let action = opt.action || null;
				let value = opt.value != undefined ? opt.value : null;
				action && this[action] && this[action](value);
			},
			payClose: function() {
				this.pay_close = false;
			},
			payOrderSuccess: function() {
			},
			setShareInfo(data){
				this.share.title = data.title
				this.share.imageUrl = data.avatar
				this.share.path = 'pages/extends/circle_create/circle_info?id='+data.id+'&spid='+this.$Cache.get('UID');
			},
		},
		//分享给朋友
		onShareAppMessage(res) {
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage']
			});
			if (!this.share.path) {
				this.share.path = 'pages/index/index?spid='+this.$Cache.get('UID')
			}
			return {
				title: this.share.title,
				path: this.share.path,
				imageUrl: this.share.imageUrl || '',
				success(res) {
					console.log(res)
				},
				fail(res) {
					console.log(res)
				}
			}
		},
		onReachBottom() {
			this.getUseListCircle();
		},
	}
</script>

<style scoped lang="scss">
	.navTabBox{
		background: #fff;
		height: 90rpx;
	}
	.longTab{
		display: flex;
		text-align: center;
		padding: 30rpx 0;
	}
	.tab-item{
		width: 50%;
		display: inline-block;
		line-height: 44rpx;
		position: relative;
		text{
			position: relative;
			display: inline-block;
			font-size: 32rpx;
			font-weight: 400;
			color: #1C211D;
		}
	}
	.tab-item.on{
		color: var(--view-theme);
		text{
			font-weight: 500;
		}
		&:before{
			content: "";
			display: inline-block;
			width: 192rpx;
			height: 22rpx;
			background-color: var(--view-theme);
			position: absolute;
			left: 25%;
			bottom: 0;
		}
	}
	.create-circle {
		background-color: #DADADA;
		border-radius: 15rpx;
		position: fixed;
		bottom: 0;
		left: 0;
		right: 0;
		.create-circle-btn {
			width: 50%;
			padding: 30rpx 0;
			text-align: center;
			font-size: 36rpx;
			font-weight: 500;
			color: #2C2C2C;
			background-color: #FFE103;
			margin-left: auto;
		}
	}
	.circle-item {
		background: #fff;
		margin: 20rpx 30rpx 0;
		padding: 30rpx;
		.circle-item-top {
			display: flex;
			justify-items: center;
		}
		.circle-item-avatar image {
			width: 160rpx;
			height: 160rpx;
		}
		.circle-item-info {
			margin-left: 20rpx;
			padding-top: 10rpx;
			flex: 1;
			overflow: hidden;
			.circle-item-title {
				font-size: 36rpx;
				font-weight: bold;
				overflow: hidden;
				white-space: nowrap;
				text-overflow: ellipsis;
			}
			.circle-item-gz {
				display: flex;
				align-items: center;
				margin-top: 12rpx;
				.circle-item-gz-icon {
					width: 28rpx;
					height: 28rpx;
				}
				.circle-item-gz-num {
					font-size: 24rpx;
					font-weight: 400;
					color: #323232;
					line-height: 34rpx;
					margin-left: 4rpx;
				}
			}
			.circle-item-gz-user {
				display: flex;
				align-items: center;
				margin-top: 20rpx;
				image {
					width: 44rpx;
					height: 44rpx;
					border-radius: 100%;
					margin-left: -10rpx;
				}
				image:first-child {
					margin-left: 0rpx;
				}
			}
			.circle-item-label_name {
				margin-top: 10rpx;
				font-size: 30rpx;
			}
			.circle-item-gz-tl {
				font-size: 20rpx;
				font-weight: 400;
				color: #323232;
				line-height: 28rpx;
				margin-left: 10rpx;
			}
		}
		/* .circle-item-button {
			margin-left: auto;
			display: flex;
			align-items: center;
			.circle-item-button_btn {
				padding: 16rpx 42rpx;
				background: #FFE103;
				border-radius: 37rpx;
				font-size: 30rpx;
				font-weight: 500;
				color: #1C211D;
				line-height: 42rpx;
				margin-top: 10rpx;
			}
		} */
		.circle-item-button2 {
			margin-left: auto;
			display: flex;
			flex-direction: column;
			justify-content: center;
			.circle-item-status {
				text-align: right;
			}
			.c-ok {
				color: #5cb85c;
			}
			.c-no {
				color: #d9534f;
			}
			.c-status {
				color: #f0ad4e;
			}
			.circle-item-button-b {
				/* display: flex;
				flex-direction: row-reverse;
				margin-top: auto; */
				.circle-item-button_btn {
					padding: 16rpx 42rpx;
					background: #FFE103;
					border-radius: 37rpx;
					font-size: 30rpx;
					font-weight: 500;
					color: #1C211D;
					line-height: 42rpx;
					margin-top: 10rpx;
					text-align: center;
					font-weight: bold;
				}
				.is_user_circle {
					background-color: #53BB47;
					color: #030502;
				}
			}
		}
		.circle-item-fail-msg {
			border-top: 1rpx solid #ccc;
			margin-top: 20rpx;
			padding-top: 20rpx;
			color: #403939c4;
		}
	}
	.noCommodity{
		width: 100%;
		.pictrue{
			margin: 0 auto;
		}
	}
	.more_btn {
		justify-content: end;
		.circle-item-button_btn {
			padding: 5rpx 18rpx;
			background: #FFE103;
			border-radius: 30rpx;
			font-size: 26rpx;
			font-weight: 500;
			color: #1C211D;
			line-height: 42rpx;
			margin-top: 10rpx;
			text-align: center;
		}
		.left_btn {
			grid-gap: 10rpx;
		}
		.right_btn {
			margin-left: auto;
			grid-gap: 10rpx;
		}
	}
</style>
